﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace EBA.Dynamic
{
    /// <summary>
    /// 属性动态生成信息
    /// </summary>
    public class PropertyEmitData
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="type"></param>
        /// <param name="property"></param>
        public PropertyEmitData(Type type, PropertyInfo property)
        {
            this.TargetType = type;
            this.PropertyInfo = property;
            this.Prefix = type.Name;
        }

        /// <summary>
        /// 类型显示实现前缀
        /// </summary>
        public string Prefix { get; private set; }

        /// <summary>
        /// 属性所在类型信息
        /// </summary>
        public Type TargetType { get; private set; }
        /// <summary>
        /// 属性信息
        /// </summary>
        public PropertyInfo PropertyInfo { get; private set; }
        MethodInfo _GetMethod;
        /// <summary>
        /// 取值方法
        /// </summary>
        public MethodInfo GetMethod
        {
            get
            {
                if (this._GetMethod == null)
                {
                    this._GetMethod = this.TargetType.GetMethod("get_" + this.PropertyInfo.Name);
                }

                return this._GetMethod;

            }
        }


        MethodInfo _SetMethod;
        /// <summary>
        /// 赋值方法
        /// </summary>
        public MethodInfo SetMethod
        {
            get
            {
                if (this._SetMethod == null)
                {
                    this._SetMethod = this.TargetType.GetMethod("set_" + this.PropertyInfo.Name);
                }

                return this._SetMethod;

            }
        }
    }

}

